package com.hongning.railway.ui.main.mine.experience.itemviewmodel;

import android.databinding.Observable;
import android.databinding.ObservableField;
import android.os.Bundle;
import android.support.annotation.NonNull;

import com.hongning.railway.app.Constant;
import com.hongning.railway.entity.resbean.ResExperienceBean;
import com.hongning.railway.ui.main.mine.experience.ExperienceFragmentViewModel;
import com.hongning.railway.ui.main.mine.experience.ExperiencePubOrEditFragment;
import com.hongning.railway.util.TimeUtils;

import me.goldze.mvvmhabit.base.ItemViewModel;
import me.goldze.mvvmhabit.binding.command.BindingAction;
import me.goldze.mvvmhabit.binding.command.BindingCommand;

public class ExperienceItemViewModel extends ItemViewModel<ExperienceFragmentViewModel> {
    public ObservableField<String> title = new ObservableField<>();
    public ObservableField<String> content = new ObservableField<>();
    public ObservableField<String> time = new ObservableField<>();
    private ResExperienceBean.SelectResultBean itemdata;
    public BindingCommand itemClick = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            Bundle bundle = new Bundle();
            bundle.putParcelable(Constant.EXTRA_DATA,itemdata);
            viewModel.startContainerActivity(ExperiencePubOrEditFragment.class.getCanonicalName(),bundle);
        }
    });
    public ExperienceItemViewModel(@NonNull ExperienceFragmentViewModel viewModel, ResExperienceBean.SelectResultBean data) {
        super(viewModel);
        this.itemdata = data;
        title.set(data.getExperiencetitle());
        content.set(data.getExperiencecontent());
        time.set(TimeUtils.getFormatTime(data.getCreatedate()));
    }
}
